//
//  PointMallViewCell.m
//  Lmm_IOS
//
//  Created by 张哲炜 on 2018/9/19.
//  Copyright © 2018年 lmm. All rights reserved.
//

#import "PointMallViewCell.h"

@interface PointMallViewCell (){
    
    UIView *middleLine;
    UIView *bottomLine;
    
    UILabel *goodsNameLabel;
    UIImageView * goodsImageView;
    UILabel *pointLabel;
    UIButton *button;
    
}

@end

@implementation PointMallViewCell




-(void)setModel:(PointGoodsModel *)pointGoodsModel {
    
    [ self->goodsImageView sd_setImageWithURL:[NSURL URLWithString:pointGoodsModel.img_url]
                      placeholderImage:nil];
    
    self->goodsNameLabel.text  = pointGoodsModel.name;
    
    //积分
     NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%d积分", pointGoodsModel.points]];
    self->pointLabel.attributedText = str;
    
    
    if (pointGoodsModel.number == 0){
        
        [self->button setTitle:@"已抢完" forState:UIControlStateNormal];
        [self->button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
         self->button.backgroundColor =[UIColor grayColor];
        
    }else{
        
        [self->button setTitle:@"立刻兑换" forState:UIControlStateNormal];
        [self->button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        self->button.backgroundColor = UIColorFromRGB(0xE65650);
       
    }

}




- (id)initWithFrame:(CGRect)frame {
    
    if (self = [super initWithFrame:frame]) {
        
        self->middleLine = UIView.new;
        //self->middleLine.hidden = YES;
        self->middleLine.backgroundColor =[UIColor grayColor];
        [self addSubview:self->middleLine];
        
        [self->middleLine makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.top).offset(0);
            make.right.equalTo(self.right).offset(0);
            make.bottom.equalTo(self.bottom).offset(0);
            make.width.equalTo(1/[[UIScreen mainScreen] scale]);
            
        }];
        
        self->bottomLine = UIView.new;
        self->bottomLine.backgroundColor = [UIColor grayColor];
        [self addSubview:self->bottomLine];
        
        [self->bottomLine makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.left).offset(0);
            make.right.equalTo(self.right).offset(0);
            make.bottom.equalTo(self.bottom).offset(0);
            make.height.equalTo(1/[[UIScreen mainScreen] scale]);
            
        }];
        
        self->goodsImageView = UIImageView.new;
        [self addSubview:self->goodsImageView];
        
        [self->goodsImageView makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.left).offset(10);
            make.right.equalTo(self.right).offset(-10);
            make.top.equalTo(self.top).offset(10);
            make.height.equalTo(POINT_MALL_IMAGE_WIDTH);
        }];
        
        self->goodsNameLabel = UILabel.new;
        self->goodsNameLabel.numberOfLines = 2;
        self->goodsNameLabel.font = [UIFont systemFontOfSize:15];
        self->goodsNameLabel.textColor = [UIColor blackColor];;
        [self addSubview:self->goodsNameLabel];
        
        [self->goodsNameLabel makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self->goodsImageView.bottom).offset(10);
            make.left.equalTo(self.left).offset(10);
            make.right.equalTo(self.right).offset(-10);
        }];
        
        
        self->pointLabel = UILabel.new;
        self->pointLabel.textColor = UIColorFromRGB(0xE65650);
        self->pointLabel.font = [UIFont systemFontOfSize:15.0];
        [self addSubview:self->pointLabel];
        
        [self->pointLabel makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.left).offset(10);
            make.bottom.equalTo(-10);
        }];
        
        self->button = UIButton.new;
        self->button.userInteractionEnabled = NO;
        self->button.layer.cornerRadius = 12;
        //self->button.backgroundColor = UIColorFromRGB(0xE65650);
        self->button.contentEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 10);
        //[self->button setTitle:@"立刻兑换" forState:UIControlStateNormal];
        //[self->button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        self->button.titleLabel.font = [UIFont systemFontOfSize:14];
        [self addSubview:self->button];
        
        [self->button makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.right).offset(-10);
            make.height.equalTo(24);
            make.bottom.equalTo(self.bottom).offset(-10);
            make.width.equalTo(80);
        }];
    }
    return self;
}

@end
